const tree_menu=(state,getters)=>{
    let cate_1st = state.flat_menu.filter((item) => item.parent_id == 0);
    let treeData = convert(cate_1st, state.flat_menu);
    return [{
        menu_name: '全部路由',
        permission_id: -1,
        resource_type_name: '根菜单',
        permission_remark: '根菜单',
        children: treeData,
    }]
}

function convert(arr, origin) {
    return arr.map((parent) => {
        let children = origin.filter((child) => parent.permission_id === child.parent_id);
        if (children.length) {
            return { ...parent, children: convert(children, origin) };
        } else {
            return { ...parent };
        }
    });
}

export default{tree_menu}